import Vue from 'vue'
import VueRouter from 'vue-router'
// 注意点: 通过 improt xxx from xxx的方式加载组件, 无论组件有没有被用到, 都会被加载进来
// import Recommend from '../views/Recommend'
// import Rank from '../views/Rank'
// import Singer from '../views/Singer'
// import Search from '../views/Search'

Vue.use(VueRouter)

const Recommend = (resolve)=>{
  import('../views/Recommend').then((moduel)=>{
   resolve(moduel);
  })
}

const Detail = (resolve)=>{
  import('../components/Detail').then((moduel)=>{
   resolve(moduel);
  })
}

const Search = (resolve)=>{
  import('../views/Search').then((moduel)=>{
   resolve(moduel);
  })
}

const Rank = (resolve)=>{
  import('../views/Rank').then((moduel)=>{
   resolve(moduel);
  })
}

const Singer = (resolve)=>{
  import('../views/Singer').then((moduel)=>{
   resolve(moduel);
  })
}
const Account = (resolve)=>{
  import('../views/Account').then((moduel)=>{
   resolve(moduel);
  })
}

const routes = [
 {path:'/',redirect:'/recommend'},
 {
  path: '/recommend',
  component: Recommend,//推荐
  children:[
    {path:'detail/:id/:type',component:Detail}//最新歌单?最新专辑
  ]
},
 {path:'/search',component:Search}, //搜索
 {
    path:'/rank',
    component:Rank,
    children:[
      {path:'detail/:id/:type',component:Detail}
    ]
  }, //排行
 {
   path:'/singer',
   component:Singer,
   children:[
     {path:'detail/:id/:type',component:Detail}
   ]
}, //歌手
 {path:'/account',component:Account}, //个人中心
]

const router = new VueRouter({
  mode: 'history',
  // mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
